package net.bac.sbe.web.sonar.server.service.locator;

import net.bac.sbe.common.sonar.config.init.SbeSonarMetricsInfoInit;
import net.bac.sbe.critical.item.init.CriticalItemInfoInit;
import net.bac.sbe.svn.init.SVNBrowserInitConfiguration;
import net.bac.sbe.web.report.config.init.ReportManagerConfigurationInit;
import net.bac.sbe.web.sonar.server.init.ServiceInitConfiguration;

import com.google.inject.Guice;
import com.google.inject.Injector;

public class ServiceFactory {

	private ServiceFactory(){
	}

	private static ServiceFactory instance = new ServiceFactory();

	private Injector injector;

	public void initInjector(){
		if (null == injector){
			injector = Guice.createInjector(
					new CriticalItemInfoInit(),
					new SVNBrowserInitConfiguration(),
					new ServiceInitConfiguration(),
					new SbeSonarMetricsInfoInit(),
					new ReportManagerConfigurationInit());
		}
	}

	private static ServiceFactory getInstance(){
		instance.initInjector();
		return ServiceFactory.instance;
	}

	public static <T> T getServiceInstance(Class<T> clazz) {

		return (T)getInstance().injector.getInstance(clazz);
	}


}
